package com.bang.study.absfactory;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;


/**
 * @ClassName: App
 * @author: BANG
 * @Date: 2019/10/28 14:52
 * @Version: 1.0
 * @Modified By:
 * @Desc: TODO
 */
@Data
@Slf4j
public class App {

    private Army army;

    private King king;

    private Castle castle;

    public void createKingdom(final KingdomFactory kingdomFactory) {
        setKing(kingdomFactory.createKing());
        setArmy(kingdomFactory.createArmy());
        setCastle(kingdomFactory.createCastle());
    }

    public static class FactoryMaker {
        public enum KingdomType {
            HUMAN, ELF;
        }

        public static KingdomFactory makeFactory(KingdomType kingdomType) {
            switch (kingdomType) {
                case HUMAN:
                    return new HumanKingdomFactory();
                case ELF:
                    return new ElfKingdomFactory();
                default:
                    throw new IllegalArgumentException("KingdomType not supported.");
            }
        }
    }

    public static void main(String[] args) {
        App app = new App();
        app.createKingdom(FactoryMaker.makeFactory(FactoryMaker.KingdomType.HUMAN));
        log.error(app.getKing().getDescription());
        log.error(app.getArmy().getDescription());
        log.error(app.getCastle().getDescription());

        log.error("=================================================");

        app.createKingdom(FactoryMaker.makeFactory(FactoryMaker.KingdomType.ELF));
        log.error(app.getKing().getDescription());
        log.error(app.getArmy().getDescription());
        log.error(app.getCastle().getDescription());
    }
}
